package cn.edu.scau.cmi.huangzhiyuan.db.client;

import java.util.List;

import cn.edu.scau.cmi.huangzhiyuan.db.domain.Person;
import cn.edu.scau.cmi.huangzhiyuan.db.domain.Teacher;
import javafx.collections.ObservableList;
import javafx.scene.control.Button;
import javafx.scene.control.ChoiceBox;
import javafx.scene.control.TextField;
import javafx.scene.layout.HBox;

public class HeaderPane extends HBox {
	public TextField nameInput;
	public ChoiceBox<Person> tutors;
	public Button addBtn;
	
	public HeaderPane() {
		setName();
		setChoiceBox();
		setButton();
		setStyle();
	}
	
	private void setName() {
		nameInput = new TextField();
		getChildren().add(nameInput);
	}
	
	private void setChoiceBox() {
		tutors = new ChoiceBox<>();
		
		getChildren().add(tutors);
	}
	
	private void setButton() {
		addBtn = new Button("保存");
		getChildren().add(addBtn);
	}
	
	private void setStyle() {
		nameInput.setPrefWidth(150);
		tutors.setPrefWidth(150);
		addBtn.setPrefWidth(100);
	}
	

	public void removeChoiceBox() {
		getChildren().remove(tutors);
		nameInput.setPrefWidth(300);
		addBtn.setPrefWidth(100);
	}
	
	public void setTutors(List<Person> teachers) {
		int selectIndex = tutors.getSelectionModel().getSelectedIndex();
		
		ObservableList<Person> items = tutors.getItems();
		items.clear();
		for(int i=0; i<teachers.size(); i++) {
			items.add(teachers.get(i));
		}
		
		tutors.getSelectionModel().select(selectIndex);
	}
}
